package com.hzit.controller;

import com.hzit.dto.StudentDTO;
import com.hzit.service.IStudentService;
import com.hzit.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/student")
public class StudentController {
	@Autowired
	private IStudentService studentService;

	//1. 列表学生
	@GetMapping("/list")
	public R list(){
		List<StudentDTO> dtos = studentService.findAll();
		return R.ok(dtos);
	}
	//2. 添加学生
	@PostMapping("/add")
	public R add(@RequestBody StudentDTO dto){
		System.out.println("dto = " + dto);
		studentService.add(dto);
		return R.ok(null,"添加学生成功！");
	}
	//3. 修改学生
	@PostMapping("/update")
	public R update(@RequestBody StudentDTO dto){
		System.out.println("dto = " + dto);
		studentService.update(dto);
		return R.ok(null,"修改学生成功！");
	}
	//4. 删除学生
	@GetMapping("/delete/{sid}")   // http://localhost:9000/student/delete/1
	public R delete(@PathVariable String sid){
		studentService.removeById(sid);
		return R.ok(null,"删除学生成功！");
	}
}
